<?php if(!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<script type="text/javascript">
	$("#content").css("background","");
<?php if (isset($pagination) && $pagination != ""):
?>
	$(".page > *,.firstPage > *").click(function(){one.changeContent(this.href);return false;});
<?php endif; if(!in_array("noSearch",$columns)):
?>
	$("#keyword").focus(function(){if(this.value == "<?php echo $this->lang->line('seachKeywordsLabel'); ?>"){this.value='';this.style.color='black';}});
	$("#keyword").blur(function(){if(this.value == ''){this.value="<?php echo $this->lang->line('seachKeywordsLabel'); ?>";this.style.color='gray';}});
	$("#search").click(function(){var keywordField = document.getElementById("keyword");if(keywordField.value == "<?php echo $this->lang->line('seachKeywordsLabel'); ?>" || keywordField.value == ""){alert("<?php echo $this->lang->line('emptySearchKeyword'); ?>");return false;}return true;});
<?php endif; if(!in_array("noDelete",$columns)):
?>
	$("#remove").click(function(){var needConfirm=false;for(var i in eles = $("input")){if(eles[i].checked){needConfirm=true;continue;}}if(!needConfirm){alert("<?php echo $this->lang->line('noItemSelected'); ?>");return false;}else{return confirm("<?php echo $this->lang->line('delete-confirm'); ?>");}});
<?php endif; if(!in_array("noSelect",$columns)):
?>
	$("#check").click(function(){
		if(typeof checked == 'undefined' || !checked)checked=true;else checked=false;for(var i in eles = $('input')){eles[i].checked=checked;};
	});
<?php endif;?>
</script>

<?php echo form_open(site_url("cp/".$listControllerName."/submitInventoryForm/".$modelName)); ?>
	<input type="hidden" name="backAfterSubmit" id="backAfterSubmit" value="<?php echo "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; ?>" />
	<table width="100%" border="0">
		<tr><td colspan="10" align="right"><?php echo (isset($pagination) && $pagination != "")?$pagination:"" ?><?php if(!in_array("noSearch",$columns)):?><input type="text" name="keyword" id="keyword" value="<?php echo ($this->input->post("keyword"))?$this->input->post("keyword"):$this->lang->line('seachKeywordsLabel'); ?>" <?php echo (!$this->input->post("keyword"))?'style="color:gray;" ':''; ?>>&nbsp;<input name="search" id="search" type="submit" value="<?php echo $this->lang->line("search"); ?>"><?php endif; ?></td></tr>
		<tr><td colspan="10" style="height:5px;"></td></tr>
		
		<tr class='list-title' style='background-image:url("<?php echo base_url()?>files/cp/icons/list-title-bg.gif");'>
			<?php if(!in_array("noSelect",$columns)):?>
			<td width="25"><img src="<?php echo base_url()?>files/cp/icons/check.gif" id="check"></td>
			<?php endif; ?>
			<?php
			$sortDescImg = "<img src='".site_url("files/cp/icons/sort-desc.gif")."'> ";
			$sortAscImg = "<img src='".site_url("files/cp/icons/sort-asc.gif")."'> ";
			
			foreach($columns as $column=>$specifications){
				if($column != "noSelect" && $column != "noDelete" && $column != "noSearch"){
					$html = "<td nowrap='nowrap'";
					if($specifications["orderable"]){
						if($sortBy == $column){
							if($sortType == "asc"){
								$html .= " title='".$this->lang->line("sortby")."' onclick=\"changeListOrder('$moduleName|$modelName','$column','desc')\"";
							}else{
								$html .= " title='".$this->lang->line("sortby")."' onclick=\"changeListOrder('$moduleName|$modelName','$column','asc')\"";
							}
						}else{
							$html .= " title='".$this->lang->line("sortby")."' onclick=\"changeListOrder('$moduleName|$modelName','$column','desc')\"";
						}
					}
					$html .= ">";
					if($sortBy == $column && $sortType == "asc") $html .= $sortAscImg;
					if($sortBy == $column && $sortType == "desc") $html .= $sortDescImg;
					$html .= $this->lang->line($column)."&nbsp;</td>";
					echo $html."\n";
				}
			}
			?>
		</tr>
		
		<?php foreach($rows as $key=>$row):?>
			<tr class="<?php echo ($key%2==0)?'list-row1':'list-row2'; ?>">
				<?php if(!in_array("noSelect",$columns)):?>
				<td><input type="checkbox" name="ids[<?php echo $row->id ?>]" value="1"></td>
				<?php endif; ?>
				<?php
				foreach($columns as $column=>$specifications){
					if($column != "noSelect" && $column != "noDelete" && $column != "noSearch"){
						$html = "<td";
						if(isset($specifications["direction"]))
							$html .= " dir='".$specifications["direction"]."'";
						if($specifications["type"] == "link"){
							$html .= " title='".$this->lang->line("edit")."'>";
							if(isset($specifications["href"]))
								$href = base_url().$specifications["href"]."/".$row->id;
							else $href = base_url()."cp/home/form/$modelName/$row->id";
							
							$html .= "<a href='$href' onclick='one.changeContent(this.href); return false;'>";
							
						}elseif($specifications["type"] == "time" && is_array($row->$column)){
							$date = $row->$column;
							$html .= " title='".$date["time"]."'>";
						}else{
							$html .= ">";
						}
						
						
						if($specifications["type"] == "thumb"){
							if(isset($specifications["href"]))
								$href = base_url().$specifications["href"]."/".$row->id;
							else $href = base_url()."cp/home/form/$modelName/$row->id";
							
							if($row->$column != "")
								$html .= "<div style='margin:5px;' align='center'><a href='$href' onclick='one.changeContent(this.href); return false;'><img border='0' src='".$row->$column."'></a></div>";
						}elseif($specifications["type"] == "boolean"){
							$html .= ($row->$column)?$this->lang->line("yes"):$this->lang->line("no");
						}elseif($specifications["type"] == "time" && is_array($row->$column)){
							$html .= $date["date"];
						}elseif($specifications["type"] == "refrenceID"){
							$titleField = $specifications["titleField"];
							$html .= $row->$titleField;
						}else{
							$html .= $row->$column;
						}
						
						if($specifications["type"] == "link"){
							$html .= "</a>";
						}
						
						$html .= "</td>";
						
						echo $html."\n";
					}
				}
				?>
			</tr>
		<?php endforeach;?>
		
		<tr><td colspan="10"><hr noshade="noshade"></td></tr>
		<tr><td colspan="10" align="right"><?php echo (isset($pagination) && $pagination != "")?$pagination:"" ?><?php if(!in_array("noDelete",$columns)): ?><input name="remove" id="remove" type="submit" value="<?php echo $this->lang->line("delete-button"); ?>"><?php endif; ?></td></tr>
	</table>
<?php echo form_close(); ?>